<section class="content-header">
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
        <li><a href="#">通道管理</a></li>
        <li class="active">支付通道管理</li>
    </ol>
</section>

<!-- Main content -->
<section class="content">
    <div class="jax-box">
        <form id="selectForm" class="form-inline" th:action="@{/tradeChan/tradeChanList}" role="form">
            <div class="form-group">

                <div class="form-group">
                    <label class="control-label">商户编号：</label>
                    <div class="control-inline">
                        <input type="text" name="mchId" class="form-control width-90" />
                    </div>
                </div>

                <shiro:hasPermission name="tradeChan:tradeChanList">
                    <div class="btn-group btn-group-sm" style="text-align:left;">
                        <button type="button" id="btn_query" class="btn btn-info">查询</button>
                        <button type="reset" id="btn_reset" class="btn btn-warning">重置</button>
                    </div>
                </shiro:hasPermission>
            </div>
        </form>
    </div>
    <div class="jax-box jax-box-table">
        <div id="toolbar" class="toolbar btn-group">
            <shiro:hasPermission name="tradeChan:add">
                <button id="btn_add" type="button" class="btn btn-primary" data-toggle="modal" data-target="#agentModal">
                    <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增
                </button>
            </shiro:hasPermission>
            <shiro:hasPermission name="tradeChan:batchDelete">
                <button id="btn_batch_delete" type="button" class="btn btn-danger">
                    <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>批量删除
                </button>
            </shiro:hasPermission>
        </div>


        <div class="wrapper-content">
            <div class="ibox-content animated fadeInRight">
                <div class="jqGrid_wrapper">
                    <table id="table_list"></table>
                    <div id="pager_list"></div>
                </div>
            </div>
        </div>

    </div>
</section>

<!-- 支付通道详情模态框 -->
<div id="tradeChanDetailModal" class="modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">支付通道信息</h4>
            </div>
            <div class="modal-body">
                <div id="tradeChanOpenWindow">
                </div>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div>

<script type="text/javascript">
    $(document).ready(function () {

        var detailFlag = "[[${@perms.hasPerm('tradeChan:detail')}]]";

        var dataGrid = new DataGrid({

            dataGrid: $('#table_list'),
            searchForm: $('#selectForm'),
            dataGridPage: $('#pager_list'),
            multiselect: true,
            multiboxonly: true,
            rownumbers: true,
            rownumWidth: 60,
            colModel: [
                {
                    header: '商户编号',
                    name: 'mchId',
                    index: 'mchId',
                    sortable: false,
                    width: 60,
                    search: false
                },
                {
                    header: '通道名称',
                    name: 'channelName',
                    index: 'channelName',
                    editable: false,
                    width: 60,
                    sortable: false,
                    search: false
                },
                {
                    header: '交易通道号',
                    name: 'channelNo',
                    index: 'channelNo',
                    editable: false,
                    width: 60,
                    sortable: false,
                    search: false
                },
                {
                    header: '上游商户号',
                    name: 'merchantNo',
                    index: 'merchantNo',
                    editable: false,
                    width: 60,
                    sortable: false,
                    search: false
                },
                {
                    header: '费率',
                    name: 'rate',
                    index: 'rate',
                    editable: false,
                    width: 60,
                    sortable: false,
                    search: false
                },
                {
                    header: '交易手续费',
                    name: 'free',
                    index: 'free',
                    editable: false,
                    width: 60,
                    sortable: false,
                    formatter: moneyFormat,
                    search: false
                },
                {
                    header: '业务类型',
                    name: 'service',
                    index: 'service',
                    editable: false,
                    width: 60,
                    sortable: false,
                    search: false
                },
                {
                    header: '操作',
                    name: 'operate',
                    index: 'operate',
                    width: 80,
                    align: 'center',
                    sortable: false,
                    formatter: function (cellvalue, options, rowObject) {
                        var detail = detailFlag == "true" ? '<a class="table-btn table-btn-info" href="javascript:void(0)" onclick="tradeChanDetail(' + rowObject.id + ')">详情</a>' : '';
                        return detail;
                    }
                }
            ]
        });

        //加载表格
        $("#btn_query").click(function () {
            $("#table_list").jqGrid('setGridParam', {
                datatype: 'json',
                postData: {
                    mchId: $('input[name=mchId]').val()
                }, // 发送数据
                page: 1
            }).trigger("reloadGrid"); //重新载入
        });


    });



    /*详情*/
    function tradeChanDetail(tradeChanId) {
        Core.load("#tradeChanOpenWindow", ctxPath + "/tradeChan/detail?&tradeChanId=" + tradeChanId, function () {
            $("#tradeChanDetailModal").modal("show");
        }, 2);
    }


    function moneyFormat(cellValue) {
        if (cellValue == null || cellValue == '') {
            cellValue = 0;
        }
        cellValue = cellValue.toFixed(2);
        var total_p = "￥" + cellValue;

        return total_p;
    }


</script>